package com.ajax.dao.impl;

import com.ajax.bean.User;
import com.ajax.dao.UserDao;
import com.ajax.util.DruidUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class UserDaoImpl extends DruidUtil implements UserDao {
    @Override
    public List<User> getAll() {
        List list = new ArrayList();
        try {
            String sql = "select * from user";
            ResultSet resultSet = query(sql, null);
            while(resultSet.next()){
                User user = new User();
                user.setId(resultSet.getInt("uid"));
                user.setUname(resultSet.getString("uname"));
                user.setUpass(resultSet.getString("upass"));
                user.setUphone(resultSet.getString("uphone"));
                list.add(user);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeAll();
        }

        return list;
    }
}
